a1be61ca6efd4a91224ebe6ca8c6d6f68a259dea,src/core/ArcadeMachine.java,ArcadeMachine,replayGame,#String#String#boolean#String#,300
Before Change
}
//Get the score for the result.
return toPlay.handleResult();
}
}
After Change
}
//Get the score for the result.
double result[] = toPlay.handleResult();
toPlay.printResult();
return result;
}
}
int seed = 0;
int[] win = new int[no_players];
double[] loggedScore = new double[no_players];
int timesteps = 0;
ArrayList<Types.ACTIONS> actions = new ArrayList<Types.ACTIONS> ();
try
{
BufferedReader br = new BufferedReader(new FileReader(actionFile));
//First line should be the sampleRandom seed, winner, score and timesteps.
if (no_players < 2) {
//Single player file
String[] firstLine = br.readLine().split(" ");
seed = Integer.parseInt(firstLine[0]);
win[0] = Integer.parseInt(firstLine[1]);
loggedScore[0] = Double.parseDouble(firstLine[2]);
timesteps = Integer.parseInt(firstLine[3]);
System.out.println("Replaying game in " + game_file + ", " + level_file + " with seed " + seed +
" expecting player to win = " + (win[0] == 1) + "; score: " + loggedScore +
"; timesteps: " + timesteps);
//The rest are the actions:
String line = br.readLine();
while (line != null) {
Types.ACTIONS nextAction = Types.ACTIONS.fromString(line);
actions.add(nextAction);
//next!
line = br.readLine();
}
//Assign the actions to the player. playerID used is 0, default for single player games
((controllers.singlePlayer.replayer.Agent)players[0]).setActions(actions);
} else {
//Multi player file
// first line contains the sampleRandom seed and the timesteps.
String[] firstLine = br.readLine().split(" ");
seed = Integer.parseInt(firstLine[0]);
timesteps = Integer.parseInt(firstLine[1]);
//next line contain scores for all players, in order.
String secondLine = br.readLine();
String[] scores = secondLine.split(" ");
for (int i = 0; i < no_players; i++) {
if (scores.length > i)
loggedScore[i] = Double.parseDouble(scores[i]);
else loggedScore[i] = 0;
}
//next line contains win state for all players, in order.
String thirdLine = br.readLine();
String[] wins = thirdLine.split(" ");
for (int i = 0; i < no_players; i++) {
if (wins.length > i)
win[i] = Integer.parseInt(wins[i]);
else win[i] = 0;
}
//display information
System.out.println("Replaying game in " + game_file + ", " + level_file + " with seed " + seed +
" expecting players' win states = " + thirdLine + "; scores: " + secondLine +
"; timesteps: " + timesteps);
//next lines contain players actions, one line per game tick, actions for players in order,
//separated by spaces.
ArrayList<ArrayList<Types.ACTIONS>> act = new ArrayList<>();
for (int i = 0; i < no_players; i++) {
act.add(new ArrayList<Types.ACTIONS>());
}
String line = br.readLine();
while (line != null) {
String[] acts = line.split(" ");
for (int i = 0; i < no_players; i++) {
Types.ACTIONS nextAction = acts.length > i ? Types.ACTIONS.fromString(acts[i]) : Types.ACTIONS.ACTION_NIL;
act.get(i).add(nextAction);
}
//next!
line = br.readLine();
}
//Assign the actions to the players.
for (int i = 0; i < no_players; i++) {
((controllers.multiPlayer.replayer.Agent)players[i]).setActions(act.get(i));
}
}
}catch(Exception e)
{
e.printStackTrace();
System.exit(1);
}
//Then, (re-)play the game.
double[] score;
if(visuals)
score = toPlay.playGame(players, seed, false, 0);
else
score = toPlay.runGame(players, seed);
//Finally, when the game is over, we need to tear the player down. Actually in this case this might never do anything.
ArcadeMachine.tearPlayerDown(toPlay, players, actionFile, seed, false);
for (int i = 0; i < toPlay.getNoPlayers(); i++) {
int actualWinner = (toPlay.getWinner(i) == Types.WINNER.PLAYER_WINS ? 1 : 0);
if (actualWinner != win[i] || score[i] != loggedScore[i] || timesteps != toPlay.getGameTick())
throw new RuntimeException("ERROR: Game Replay Failed.");
}
double result[] = toPlay.handleResult();
toPlay.printResult();
return result;
}